package com.miplus.ccrm.report.controller;

import com.miplus.ccrm.common.CmdResVo;
import com.miplus.ccrm.common.JPubUtils;
import com.miplus.ccrm.common.R;
import com.miplus.ccrm.report.controller.vo.evt.AiCallListVo;
import com.miplus.ccrm.report.controller.vo.evt.AiCallRetVo;
import com.miplus.ccrm.report.controller.vo.evt.CtiCallEvtVo;
import com.miplus.ccrm.report.controller.vo.rdo.SmsCodeVo;
import com.miplus.ccrm.report.feign.ICoreFeign;
import com.miplus.ccrm.report.security.JCommonData;
import com.miplus.ccrm.report.service.cti.CtiCallhistService;
import com.miplus.ccrm.report.utils.SpringContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 3-1.接收第三方数据接口
 */
@Slf4j
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/do")
public class DoController {

    @Resource
    private CtiCallhistService callhistService;

    //@Resource
    //private ICoreFeign iCoreFeign;

    @Resource
    private JCommonData jCommonData;

    /**
     * 接收CTI消息
     */
    @PostMapping("/ctiCallEvent")
    public R<CmdResVo> ctiCallEvent(@RequestBody @Validated CtiCallEvtVo ctiCallEvtVo) {
        log.info("ctiCallEvent:{}",ctiCallEvtVo);
        return R.Success(callhistService.callAdd(ctiCallEvtVo));
    }

    /**
     * 接收AI外呼结果消息
     */
    @PostMapping("/aiCallResult")
    public R<CmdResVo> aiCallResult(@RequestBody @Validated AiCallRetVo aiCallRetVo) {
        log.info("aiCallResult:{}",aiCallRetVo);
        //String token = SpringContextUtil.getBearerToken();
        //return iCoreFeign.saveAiListResult(aiCallRetVo,token);
        return R.Success(new CmdResVo(0));
    }

    /**
     * 接收AI外呼批量结果消息
     */
    @PostMapping("/aiCallListResult")
    public R<CmdResVo> aiCallListResult(@RequestBody @Validated AiCallListVo aiCallListVo) {
        log.info("aiCallListResult:{}",aiCallListVo);
        int ret=0;
        if(JPubUtils.IsNotEmpty(aiCallListVo.getCallList())){
            ret=aiCallListVo.getCallList().size();
        }
        return R.Success(new CmdResVo(ret,aiCallListVo.getBatchId()));
    }

    /**
     * 发送短信验证码
     */
    @PostMapping("/sendSmsCode")
    public R<CmdResVo> sendSmsCode(@RequestBody @Validated SmsCodeVo smsCodeVo) {
        return R.Success(callhistService.sendSmsCode(smsCodeVo.getUsrid(),jCommonData));
    }
}
